oracle中日期类型与unix 时间戳的转换 | 您所在的位置:网站首页 › oracle 日期转时间戳 › oracle中日期类型与unix 时间戳的转换 |
Oracle中的时间是Date型,以下函数提供了两种时间转换的Oracle函数 (1)从Unix时间戳记转换为Oracle时间 create or replace function unix_to_oracle(in_number NUMBER) return date is begin return(TO_DATE('19700101','yyyymmdd') + in_number/86400 +TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))/24); end unix_to_oracle; (2)由Oracle时间Date型转换为Unix时间戳记 create or replace function oracle_to_unix(in_date IN DATE) return number is begin return( (in_date -TO_DATE('19700101','yyyymmdd'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))*3600); end oracle_to_unix;
使用 select unix_to_oracle(1315102978) from dual; select oracle_to_unix(to_date('2011-09-04 10:22:58','yyyy-mm-dd hh24:mi:ss')) from dual;
其它时间戳
date -d @1281161747 实现时间戳 → 普通时间 date +%s -d"20110904 10:22:00" 实现普通时间→至时间戳 mysql下执行 SELECT UNIX_TIMESTAMP('2011-09-04 10:22:00');实现普通时间→至时间戳 SELECT FROM_UNIXTIME(875996580); 实现时间戳 → 普通时间 |
CopyRight 2018-2019 实验室设备网 版权所有 |